# -*- coding: utf-8 -*

import os
import sys

from pystardict import Dictionary
from dictapi import *

reload(sys)
sys.setdefaultencoding('utf-8') 

class StarDictAPI(DictAPI):
    def __init__(self, dict_name, dict_dir, dict_file):
        DictAPI.__init__(self, dict_name)
        self.dicts_dir = os.path.join(os.path.dirname(__file__))
        self.dict = Dictionary(os.path.join(self.dicts_dir, dict_dir, dict_file))

    def translate(self,word):
        self.result.lookup_word = word
        try:
            self.result.define = self.dict.dict[word]
        except KeyError:
            self.result.define = 'Not Found'
